#include <stdio.h>
#include <sys/time.h>
#include "src/vk_type.h"
#include "src/vkern.h"

uint32_t sys_tick(void)
{
	struct timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}

int task_test(void* data)
{
	printf("task running %d!\r\n", vtask_runnning());
	return 0;
}
task_regist(2, 1000, task_test);

static void kern_init()
{
	if (vkern_init(sys_tick, 1) == KE_OK)
	{
		printf("kern init success!\r\n");
	}
	else  
	{
		printf("kern init fail!\r\n");
	}
}
init_export(kern_init);

int main(void)
{
#if defined (KERN_USING_EXPORT) && !defined (KERN_EXPORT_NOT_SUSPORT)
	init_execute();
	task_execute();
#else 
	if (vkern_init(sys_tick, 1) == KE_OK)
	{
		printf("kern init success!\r\n");
	}
	else  
	{
		printf("kern init fail!\r\n");
	}
	vtask_create_dynamic(2, VTASK_STATE_READY, 1000, task_test);
#endif

	vtask_list(0);

	while (1)
	{
		vtask_schedule();
	}
	return 0;
}
